<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt="http://exslt.org/common"
  xmlns:url="http://xmlns.heustics.org/xslt/ext/urllib/0.1/"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="&a;"
  xmlns:o="&a;query#"
  xmlns:e="&a;editor-common#"
  xmlns:w="http://xmlns.heustics.org/xslt/ext/wiki/0.1/"
  extension-element-prefixes="w url"
  exclude-result-prefixes="xsl exslt url o e a l"
> 
  <!-- xsl:import href="layout.xslt"/ -->
  <xsl:import href="basic.xslt"/>
  <!-- xsl:import href="options.xslt"/ -->
  <xsl:import href="editor-common.xslt"/>
  
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;query')"/>
  <xsl:variable name="o:params-l10n" select="$o:l10n/*[@name='params']/*"/>
  <xsl:variable name="o:hints-l10n" select="$o:l10n/*[@name='hints']/*"/> 
  <xsl:variable name="o:submits-l10n" select="$o:l10n/*[@name='submits']/*"/>
  
  <xsl:variable name="o:theme" select="a:get-l10n('&a;query#base-theme')"/>
    
  <xsl:template match="a:form" mode="a:form-header">
    <xsl:param name="key" select="@status-type"/>
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='status-types']/*"/>
    <xsl:variable name="status" select="$l10n[@key=$key]"/>
    <xsl:choose>
      <xsl:when test="$status">
        <div class="entry status">
          <span><xsl:value-of select="$status"/></span>
          <div class="spacer"/>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-imports/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>  
    
  <xsl:template match="a:*[@node-id]" mode="a:main-instance" name="o:main-instance">  
    <xsl:param name="event" select="/*/a:content/a:form/@event"/>
    <xsl:variable name="url">
      <xsl:apply-templates select="a:search-params" mode="a:search-url-str"/>
    </xsl:variable>    
    <!-- xsl:if test="not(a:search-results)">
      <xsl:apply-templates select="." mode="a:input-methods"/>
    </xsl:if -->
    <xsl:apply-templates mode="a:input-show">
       <xsl:with-param name="url" select="concat($url,'&amp;search=',$event,'&amp;event=',$event)"/>
       <!-- removed quick-search=1&amp; -->
    </xsl:apply-templates>   
  </xsl:template>   
  
  <xsl:template match="a:search-params" mode="a:search-url-str">
    <xsl:value-of select="a:format-repeat-request()"/>
    <xsl:apply-templates mode="a:search-url-param-str"/>
  </xsl:template>
  
  <xsl:template match="*" mode="a:search-url-param-str">
    <xsl:if test="string-length(.)">
      <xsl:value-of select="concat('&amp;',local-name(),'=',url:quote(.))"/>
    </xsl:if>
  </xsl:template>
   
  <xsl:template match="*[a:selection]" mode="a:search-url-param-str">
    <xsl:variable name="name" select="local-name()"/>
    <xsl:for-each select="a:selection/*">
      <xsl:value-of select="concat('&amp;',$name,'=',url:quote(@key))"/>
    </xsl:for-each>
  </xsl:template>
  
  <xsl:template match="*[@selected]" mode="a:search-url-param-str">
    <xsl:value-of select="concat('&amp;',local-name(),'=',url:quote(@selected))"/>
  </xsl:template>  
  
  <xsl:template match="a:search-params" mode="a:input-show">    
    <xsl:apply-templates mode="a:input-hidden"/>
  </xsl:template>
  
  <xsl:template match="a:default-graphs" mode="a:search-url-param-str"/> 
  <xsl:template match="a:default-graphs" mode="a:input-hidden"/> 
  <xsl:template match="a:default-graphs" mode="a:input-show"> 
    <xsl:param name="l10n" select="$o:l10n/*[@name='default-graphs-ext']/*"/>    
    <div class='input textarea query'>      
      <div class='key'>
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='default-graphs']"/></span>
          <div class="spacer"/>
        </div>
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='default-graphs']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">          
          <xsl:choose>
            <xsl:when test="*">
              <span>
                <xsl:variable name="markup" select="$l10n[@key='has-defaults']"/>
                <w:render-markup select="string($markup)" 
                  mime-type="{$markup/@format}"
                  url-params-string='{$a:common-url-params}' 
                  url-resource-ext='{$a:resource-ext}'/>
              </span>
              <ul>
                <xsl:for-each select="*">
                  <li>
                    <xsl:choose>
                      <xsl:when test="@uri">
                        <a href="{a:format-url(a:public-url(@uri))}" title="{$l10n[@key='description-link-title']}">
                          <xsl:value-of select="."/>
                        </a>
                      </xsl:when>    
                      <xsl:otherwise>
                        <span>
                          <xsl:value-of select="."/>
                        </span>
                      </xsl:otherwise>                  
                    </xsl:choose>
                    <div class="spacer"/>                   
                  </li>
                </xsl:for-each>
              </ul>
            </xsl:when>
            <xsl:otherwise>
              <span>
                <xsl:variable name="markup" select="$l10n[@key='no-defaults']"/>
                <w:render-markup select="string($markup)" 
                  mime-type="{$markup/@format}"
                  url-params-string='{$a:common-url-params}' 
                  url-resource-ext='{$a:resource-ext}'/>
              </span>
            </xsl:otherwise>
          </xsl:choose>          
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>    
  </xsl:template> 
  
  <xsl:template match="a:query" mode="a:input-show" name="a:query-input-show"> 
    <xsl:param name="help-markup"/>
    <div class='input textarea query'>      
      <div class='key'>
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='query']"/></span>
          <div class="spacer"/>
        </div>
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='query']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <textarea class="max" name="query" cols="50" rows="25">
            <xsl:value-of select="."/>
          </textarea>
          <div class="spacer"/>
        </div>     
        <xsl:if test="$help-markup">
          <div class="entry help query-help">
            <w:render-markup select='string($help-markup)' 
              mime-type="{$help-markup/@format}"
              url-params-string='{$a:common-url-params}' 
              url-resource-ext='{$a:resource-ext}'/>
            <div class="spacer"/>
          </div>  
        </xsl:if> 
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
    
  </xsl:template> 
  
  <xsl:template match="a:nsmaps" mode="a:input-show"> 
    <xsl:param name="help-markup" select="$o:hints-l10n[@key='nsmaps-help-markup']"/>
    <div class='input textarea nsmaps'>      
      <div class='key'>
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='nsmaps']"/></span>
          <div class="spacer"/>
        </div>
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='nsmaps']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <textarea class="max" name="nsmaps" cols="50" rows="25">
            <xsl:value-of select="."/>
          </textarea>
          <div class="spacer"/>
        </div>     
        <xsl:if test="$help-markup">
          <div class="entry help nsmaps-help">
            <w:render-markup select='string($help-markup)' 
              mime-type="{$help-markup/@format}"
              url-params-string='{$a:common-url-params}' 
              url-resource-ext='{$a:resource-ext}'/>
            <div class="spacer"/>
          </div>  
        </xsl:if> 
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
    
  </xsl:template> 
    
  <xsl:template match="a:search-results" mode="a:input-show">
    <xsl:param name="url"/>
    <div class="search_results">
      <xsl:apply-templates mode="a:search-results">
        <xsl:with-param name="url" select="$url"/>
      </xsl:apply-templates>
      <div class="spacer search_results_spacer"/>
    </div>   
  </xsl:template>
  
  <xsl:template match="a:submit[@key='search' or @key='refresh' or @key='change-query']">    
    <xsl:param name="name"/>    
    <xsl:param name='key' select='@key'/>
    <div class="input submit">
      <xsl:variable name='val' select='$o:submits-l10n[@key=$key]'/>
      <input type='hidden' name='{$key}' value='{$val}'/>
      <input type='submit' name='{$name}' value='{$val}'/>
      <div class='spacer'/>
    </div>        
  </xsl:template> 
  
  <xsl:template match="*" mode="a:form-related-request">
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='form-related-requests']/*"/>
    <div class="form-related-request form-reset">
      <a href="{a:format-reset-request()}">
        <xsl:value-of select="$l10n[@key='reset']"/>
      </a>
      <div class="spacer"/>
    </div>
  </xsl:template>
  
</xsl:stylesheet>

